/*******************************************************************************
 * Copyright 2013 Mindaugas Idzelis
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package incontrol.bf3.packets;

import incontrol.bf3.protocol.requests.KickRequest;
import incontrol.bf3.protocol.requests.KillPlayerRequest;
import incontrol.bf3.protocol.requests.ListPlayersRequest;
import incontrol.bf3.protocol.requests.LogonRequest;
import incontrol.bf3.protocol.requests.MovePlayerRequest;
import incontrol.bf3.protocol.requests.BF3Request;
import incontrol.bf3.protocol.requests.SendEventsRequest;
import incontrol.rcon.protocol.Origin;
import incontrol.rcon.protocol.Packet;
import incontrol.rcon.protocol.Type;
import incontrol.rcon.protocol.Word;

import java.util.List;

public class PacketFactory {

	public Packet createPacket(BF3Request request, long seq) {
		switch (request.getRequestType()) {
		case KICK: {
			KickRequest r = ((KickRequest) request);
			Packet p = new Packet(Origin.SERVER, Type.REQUEST, seq, r
					.getRequestType().getCommand(), r.getPlayerName(),
					r.getReason());
			return p;
		}
		case KILL: {
			KillPlayerRequest r = ((KillPlayerRequest) request);
			Packet p = new Packet(Origin.SERVER, Type.REQUEST, seq, r
					.getRequestType().getCommand(), r.getPlayerName());
			return p;

		}
		case LIST: {
			ListPlayersRequest r = ((ListPlayersRequest) request);
			String[] setWords = r.getPlayers().getBody();

			Packet p = new Packet(Origin.SERVER, Type.REQUEST, seq, r
					.getRequestType().getCommand(), setWords);
			return p;

		}
		case LOGON: {
			LogonRequest r = ((LogonRequest) request);
			Packet p = new Packet(Origin.SERVER, Type.REQUEST, seq, r
					.getRequestType().getCommand(), r.getPassword());
			return p;
		}
		case MOVE: {
			MovePlayerRequest r = ((MovePlayerRequest) request);
			Packet p = new Packet(Origin.SERVER, Type.REQUEST, seq, r
					.getRequestType().getCommand(), r.getPlayerName(),
					Integer.toString(r.getSquad().getTeamId()),
					Integer.toString(r.getSquad().getSquadId()),
					Boolean.toString(r.isKill()));
			return p;

		}
		case EVENTS: {
			SendEventsRequest r = ((SendEventsRequest) request);
			Packet p = new Packet(Origin.SERVER, Type.REQUEST, seq, r
					.getRequestType().getCommand(), Boolean.toString(r
					.isEventEnabled()));
			return p;

		}
		case INFO: {
			Packet p = new Packet(Origin.SERVER, Type.REQUEST, seq, request
					.getRequestType().getCommand());
			return p;
		}
		}
		return null;
	}
}
